import pymysql

conn = pymysql.connect(host='localhost',user='root',password='123456',database='py_sql_test1')
cursor = conn.cursor()

def createTable(sql):
    '''
    创建表结
    :param sql:
    :return:
    '''
    cursor.execute(sql)

def modifyTable(sql):
    '''
    进行insert update delete步骤
    :rtype: object
    :param sql:
    :return:
    '''
    try:
        cursor.execute(sql)
        conn.commit()
    except Exception as e:
        print(e)
        conn.rollback()

def query(sql):
    '''
    查询
    :param sql:
    :return:
    '''
    cursor.execute(sql)
    result = cursor.fetchall()
    return result